<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Delete Friend</title>
<style type="text/css">
p {font-family:Arial, Helvetica, sans-serif; font-size: 11px;}
select{ width: 150px;
}
</style>
<SCRIPT type="text/javascript" src="loadfriends.js"></SCRIPT>
<script type="text/javascript">
var http_request;
function toserver(f) {

   var sbroad = "http://silo.cs.indiana.edu:13795/servlet/DelFriendServlet?nym=home&friends=";

      var r = new Array();
      for (var i = 0; i < f.friends.options.length; i++){
        if (f.friends.options[i].selected)
                r[i] = f.friends.options[i].value;
        if(r[i]!=null) {
                var slength = r[i].length;
                r[i] = r[i].slice(1, slength-1);
                var sbroad = sbroad+r[i]+",";
                }
            }
            sblength = sbroad.length
            sbroad = sbroad.slice(0, sblength-1);
            alert(sbroad);
                loadXMLDoc2(sbroad);

}

function callback2()
        {

            try{
                 if (http_request.readyState == 4)
                   {
                    
                           if (http_request.status == 200 ){

                                        //get info from server
                                        alert(http_request.responseText);
                                        var items = [];
                                        var b1 = http_request.responseXML.getElementsByTagName('valid');
                                        var valid = b1.item(0).firstChild.nodeValue;
                                        if(valid == 1)
                                                alert("Success");
                                        else
                                                alert("Failure");

                          }
                        else
                                { alert("There was a problem with request");
 }

               }
            }

            catch( e )
            {
                alert("Catch error:" + e);
             }
   }


function loadXMLDoc2(url_var) {

        if (window.XMLHttpRequest)
        {
          http_request = new XMLHttpRequest();
          http_request.onreadystatechange = callback2;
          http_request.open('GET', url_var, true);
          http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          http_request.send("");
                      //initialize the request
     }


 else if(window.ActiveXObject){
          //Create our RequestObject
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
          if(http_request){
                http_request.onreadystatechange = function() { callback2(http_request); };
                http_request.open('GET', url_var, true);
                http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                http_request.send("");                      //initialize the request
                }
          }


        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
}


</script>
</head>

<body>
<form id="f">
  <p><strong>Current Friends</strong></p>
  <p><strong>
    <select name="friends" size="5" multiple="multiple" id="friends" style="width: 150;">
    </select>
    </strong></p>
  <p><strong>Send Friend Request To:<br />
  </strong>(seperate usernames by
  comma)</p>
  <p><strong>
    <textarea name="usernames" id="usernames" value=""></textarea>
  </strong></p>
  <p>
 <label>
    <input type="submit" name="Submit" value="Delete Friends" onclick="toserver(this.form); return false;"/>
    </label>
  </p>
</form>
</body>
</html>


